package com.teach.servlet.admin;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.teach.entity.Lj;
import com.teach.service.LjService;
import com.teach.service.impl.LjServiceImpl;

//@WebServlet("/admin/lj-update.let")
public class LjUpdateServlet extends HttpServlet{

	private LjService ljService = new LjServiceImpl();
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Lj lj = new Lj();
		lj.setLjId(Long.valueOf(request.getParameter("ljId")));
		lj.setLjName(request.getParameter("ljName"));
		lj.setLjNickname(request.getParameter("ljNickname"));
		lj.setLjPassword(request.getParameter("ljPassword"));
		lj.setLjPhone(request.getParameter("ljPhone"));
		lj.setLjQq(request.getParameter("ljQq"));
		lj.setLjSex(Boolean.valueOf(request.getParameter("ljSex")));
		try {
			lj.setLjBrithdate(new SimpleDateFormat("yyyy-mm-dd").parse(request.getParameter("ljBrithdate")));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		try {
			ljService.update(lj);
			request.setAttribute("msg", "修改用户成功");
			request.setAttribute("href", "admin/lj-list.let");
		}catch(Exception e) {
			e.printStackTrace();
			request.setAttribute("error", e.getMessage());
		}
		request.getRequestDispatcher("/admin/msg.jsp").forward(request, response);
	}
}
